---
title: Construct a new in-memory web context
summary: CreateContext end-to-end process on SAIF.Services.WCF.Services.WebContextService.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-22
operation_id: OP-011
trigger: Caller invokes `CreateContext` over the `WebContext` route, or `WebContextService.Get` calls it internally when locating the context id.
---

# OP-011: Construct a new in-memory web context

CreateContext is invoked over the `WebContext` route on `SAIF.Services.WCF.Services.WebContextService`; this page documents the process end to end, from route dispatch to the message the caller receives.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-011 |
| **Trigger** | Caller invokes `CreateContext` over the `WebContext` route, or `WebContextService.Get` calls it internally when locating the context id. |
| **Entry operation** | [`CreateContext`](../contracts/web-context-service.md#createcontext) |
| **Owning component** | `SAIF.Services.WCF.Services.WebContextService.CreateContext` |
| **Inputs** | Request message parts listed below |
| **Outputs** | A new, unpersisted web context carrying the given or generated id. |
| **Failure behavior** | No fault path documented for this operation, per [Faults and error pipeline](../faults.md) |

## Request and response

| Direction | Element | Type | Declared in | Notes |
| --- | --- | --- | --- | --- |
| Request | `contextId` | `string` | BCL (`System`) | Seed value for the new context's id; a blank value produces a fresh GUID instead. (No (default `None`)) |
| Response | `IWebContext` | `IWebContext` | External contracts assembly (`SAIF.Services.WCF.Contracts` / framework closure) ** | A new, unpersisted web context carrying the given or generated id. |

<!-- Types declared in `SAIF.Services.WCF.Contracts` are attributed to `SAIF.Framework.Core`, inferred from source and package references and marked `*`; their members are not enumerated because the external declaration was not read, marked `**`. -->

## Steps

1. Return `new WebContext(contextId)` when `contextId` is non-blank, otherwise `new WebContext(Guid.NewGuid().ToString())` ([BR-WCF-015](../business-rules.md#br-wcf-015-context-identity-comes-from-a-stored-pid-or-a-new-guid)). The concrete `WebContext` type comes from the external contracts assembly.

## Process flow

The following diagram visualizes this process's control flow.

```mermaid
flowchart TD
    A{"contextId non-blank?"}
    B["Return new WebContext(contextId)"]
    C["Return new<br>WebContext(Guid.NewGuid().ToString())"]
    A -->|"Yes"| B
    A -->|"No"| C
```

## Transaction and side effects

| Aspect | Finding |
| --- | --- |
| Unit of work | None |
| Commit point | Not applicable |
| Records written | None |
| Downstream calls | None |
| Shared state touched | None |
| Repeat-call behavior | Idempotent when `contextId` is supplied; produces a new id each call otherwise |

## Logging

| Surface | Written content |
| --- | --- |
| `ErrorLogErrorHandler` → `LogService` | Failure-path exception logging only, carrying method signature, calling user and exception detail; see [Faults and error pipeline](../faults.md) |

## Faults and error handling

| Failure | Fault type the caller receives | Produced by | Source |
| --- | --- | --- | --- |
| No exception path is documented for this operation | — | — | — |

## Authorization

| Requirement | Enforced by | Source | Applies to |
| --- | --- | --- | --- |
| [None in code](../authentication-authorization.md#authorization-enforcement) | IIS authentication on the deployment (see [Activation and hosting](../activation-hosting.md)) | `src/WCF/SAIF.Services.WCF.Host/Services/WebContextService.cs` | This operation |

## Related documentation
- [Index](../index.md)
- [Overview](../overview.md)
- [Architecture](../architecture.md)
- [Activation and hosting](../activation-hosting.md)
- [Operations](../operations.md)
- [Faults and error pipeline](../faults.md)
- [Authentication and authorization](../authentication-authorization.md)
- [Dependencies](../dependencies.md)
- [Configuration](../configuration.md)
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Data model](../data-model.md)
- [Operational runbook](../operational-runbook.md)
- [Tech debt](../tech-debt.md)

> **Note:** Statements marked with `*` were inferred from code structure, naming
> conventions, or contextual evidence where direct confirmation was not available
> in source artifacts. Statements marked with `**` could not be confirmed; treat
> as unknown until verified.

## Sources
- src/WCF/SAIF.Services.WCF.Host/Services/WebContextService.cs
